package cn.milolab.djback.controller;

import cn.milolab.djback.annotation.DJRoleCheck;
import cn.milolab.djback.bean.entity.Employee;
import cn.milolab.djback.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

/**
 * @author 叶欣委
 * 社员控制层
 */
@RestController
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    EmployeeService employeeService;

    @GetMapping
    @DJRoleCheck(Employee.RoleLevel.EMPLOYEE)
    public Map<String,Object> getEmployee(@RequestParam @Nullable Integer id , @RequestParam @NonNull String sort , @RequestParam @NonNull Integer page, @RequestParam @NonNull Integer limit ){
        return employeeService.getEmployee(id,sort,page,limit);
    }

    @PostMapping
    @DJRoleCheck(Employee.RoleLevel.SECRETARY)
    public void addEmployee(@RequestBody Employee addEmployee, @RequestAttribute Integer userId){
        employeeService.addEmployee(addEmployee,userId);
    }

    @PutMapping
    @DJRoleCheck(Employee.RoleLevel.SECRETARY)
    public void updateEmployee(@RequestBody Employee updateEmployee , @RequestAttribute Integer userId){
        employeeService.updateEmployee(updateEmployee,userId);
    }

    @DeleteMapping
    @DJRoleCheck(Employee.RoleLevel.SECRETARY)
    public void deleteEmployee(@RequestParam Integer id , @RequestAttribute Integer userId){
        employeeService.deleteEmployee(id,userId);
    }
}
